package com.taxipark.service;

import com.taxipark.domain.TaxiDriver;
import com.taxipark.domain.TaxiManager;
import com.taxipark.service.connection.ConnectionProviderImpl;

public class SimpleRegestration implements Regestration {
	private Reestr reestr = new DbSimpleReestr(new ConnectionProviderImpl("jdbc:mysql://localhost:3306/db_taxidrivers", "root", "root"));

	@Override
	public void addDriver(TaxiDriver driver, TaxiManager manager) {
		System.out.println("Adding driver: " + driver + " by manager: " + manager);

	
		driver.setManagerId(manager);
		driver.setManager(manager);
		reestr.save(driver);

		System.out.println("Driver: " + driver + "registered with id: " + driver.getId());

	}

	@Override
	public String printAllDrivers() {
		String result = "\n\nDrivers:\n";
		result = result + "-------------------\n";

		for (int i = 0; i < reestr.getAll().size(); i++) {
			result = result + reestr.getAll().get(i) + "\n";
		}

		return result;

	}

	@Override
	public void removeDriver(TaxiDriver driver) {
		System.out.println("Removing driver: " + driver);

		reestr.delete(driver);

		System.out.println("Driver: " + driver + " removed.");

	}
}
